package com.baizhi.controller;

import com.baizhi.Student;
import com.baizhi.User;
import com.baizhi.service.Userservice;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
public class UserController {
    @Autowired
    private Userservice us;
    @PostMapping("/Users")
    public Map<String,String> login(@RequestBody User user){
        System.out.println(user.getUsername());
        boolean login = us.login(user.getUsername(), user.getPassword());
        if (login){
            return new HashMap<String, String>(){{
                put("code","success");
            }};
        }
        return new HashMap<String, String>(){{
            put("code","errorPage");
        }};
    }
  @GetMapping("students/{pageIndex}")
   public PageInfo<Student> pageInfo(@PathVariable("pageIndex.")@RequestParam(required = false,defaultValue = "1") int PageIndex){
        PageInfo<Student> page = us.page(PageIndex, 3);
        return page;
    }
}
